

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>quippy.atoms &mdash; quippy 7ea04c5+ documentation</title>
  

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  
  
  

  
  <script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../_static/language_data.js"></script>
        <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
        <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "math|output_area", "processEscapes": true, "ignoreClass": "document", "inlineMath": [["$", "$"], ["\\(", "\\)"]]}})</script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/theme_overrides.css" type="text/css" />
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> quippy
          

          
            
            <img src="../../_static/hybrid.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
              <div class="version">
                7ea04c5+
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
    
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to <code class="docutils literal notranslate"><span class="pre">quippy</span></code></a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install.html">Installation of QUIP and quippy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../Tutorials/index.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quippy.html">Quippy library reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../visualisation.html">Visualisation Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fortran_wrapper.html">Appendix: wrapping Fortran 90 Code</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../teach_sparse.html">Command line options of the teach_sparse main program</a></li>
</ul>

            
          
    <p></p>
    <ul>
        <li><a href="../../genindex.html">Index</a></li>
        <li><a href="../../py-modindex.html">Module Index</a></li>
        <li><a href="../../search.html">Search Page</a></li>
        <li><a href="../index.html">Module Source Code</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">quippy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>quippy.atoms</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for quippy.atoms</h1><div class="highlight"><pre>
<span></span><span class="c1"># HQ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>
<span class="c1"># HQ X</span>
<span class="c1"># HQ X   quippy: Python interface to QUIP atomistic simulation library</span>
<span class="c1"># HQ X</span>
<span class="c1"># HQ X   Copyright James Kermode 2010</span>
<span class="c1"># HQ X</span>
<span class="c1"># HQ X   These portions of the source code are released under the GNU General</span>
<span class="c1"># HQ X   Public License, version 2, http://www.gnu.org/copyleft/gpl.html</span>
<span class="c1"># HQ X</span>
<span class="c1"># HQ X   If you would like to license the source code under different terms,</span>
<span class="c1"># HQ X   please contact James Kermode, james.kermode@gmail.com</span>
<span class="c1"># HQ X</span>
<span class="c1"># HQ X   When using this software, please cite the following reference:</span>
<span class="c1"># HQ X</span>
<span class="c1"># HQ X   http://www.jrkermode.co.uk/quippy</span>
<span class="c1"># HQ X</span>
<span class="c1"># HQ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">weakref</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">from</span> <span class="nn">math</span> <span class="k">import</span> <span class="n">pi</span><span class="p">,</span> <span class="n">sqrt</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">quippy</span> <span class="k">import</span> <span class="n">_atoms</span>
<span class="kn">from</span> <span class="nn">quippy._atoms</span> <span class="k">import</span> <span class="o">*</span>

<span class="kn">from</span> <span class="nn">quippy.dictionary</span> <span class="k">import</span> <span class="p">(</span><span class="n">T_INTEGER_A</span><span class="p">,</span> <span class="n">T_REAL_A</span><span class="p">,</span> <span class="n">T_LOGICAL_A</span><span class="p">,</span> <span class="n">T_CHAR_A</span><span class="p">,</span>
                               <span class="n">T_INTEGER_A2</span><span class="p">,</span> <span class="n">T_REAL_A2</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">quippy.table</span> <span class="k">import</span> <span class="n">TABLE_STRING_LENGTH</span>
<span class="kn">from</span> <span class="nn">quippy.oo_fortran</span> <span class="k">import</span> <span class="n">update_doc_string</span>
<span class="kn">from</span> <span class="nn">quippy.farray</span> <span class="k">import</span> <span class="n">frange</span><span class="p">,</span> <span class="n">farray</span><span class="p">,</span> <span class="n">fzeros</span><span class="p">,</span> <span class="n">fvar</span><span class="p">,</span> <span class="n">s2a</span>
<span class="kn">from</span> <span class="nn">quippy.dictmixin</span> <span class="k">import</span> <span class="n">DictMixin</span>
<span class="kn">from</span> <span class="nn">quippy.util</span> <span class="k">import</span> <span class="n">infer_format</span><span class="p">,</span> <span class="n">parse_slice</span>
<span class="kn">from</span> <span class="nn">quippy.units</span> <span class="k">import</span> <span class="n">N_A</span><span class="p">,</span> <span class="n">MASSCONVERT</span>
<span class="kn">from</span> <span class="nn">quippy.periodictable</span> <span class="k">import</span> <span class="n">ElementMass</span>
<span class="kn">from</span> <span class="nn">quippy.extendable_str</span> <span class="k">import</span> <span class="n">Extendable_str</span>
<span class="kn">from</span> <span class="nn">quippy</span> <span class="k">import</span> <span class="n">QUIPPY_TRUE</span><span class="p">,</span> <span class="n">QUIPPY_FALSE</span>
<span class="kn">from</span> <span class="nn">quippy</span> <span class="k">import</span> <span class="n">available_modules</span><span class="p">,</span> <span class="n">FortranDerivedTypes</span><span class="p">,</span> <span class="n">get_fortran_indexing</span>

<span class="n">atomslog</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;quippy.atoms&#39;</span><span class="p">)</span>
<span class="c1">#atomslog.setLevel(logging.DEBUG)</span>

<span class="vm">__doc__</span> <span class="o">=</span> <span class="p">(</span><span class="n">_atoms</span><span class="o">.</span><span class="vm">__doc__</span> <span class="o">+</span> <span class="s2">&quot;&quot;&quot;</span>

<span class="s2">This module defines the :class:`Atoms`, which stores and manipulates a</span>
<span class="s2">collection of atoms, as well as the :class:`Connection` class which stores</span>
<span class="s2">topology and neighbour lists, and the :class:`DomainDecomposition` class.</span>

<span class="s2">&quot;&quot;&quot;</span><span class="p">)</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="n">_atoms</span><span class="o">.</span><span class="n">__all__</span> <span class="o">+</span> <span class="p">[</span><span class="s1">&#39;NeighbourInfo&#39;</span><span class="p">,</span> <span class="s1">&#39;get_lattice_params_&#39;</span><span class="p">,</span> <span class="s1">&#39;get_lattice_params&#39;</span><span class="p">]</span>

<span class="k">if</span> <span class="s1">&#39;ase&#39;</span> <span class="ow">in</span> <span class="n">available_modules</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">ase</span>
    <span class="kn">from</span> <span class="nn">ase.spacegroup</span> <span class="k">import</span> <span class="n">Spacegroup</span>
    <span class="c1"># adsorbate_info as a property is deprecated in ase</span>
    <span class="c1"># since it shows up in `dir()` the methods in</span>
    <span class="c1"># oo_fortran will error when trying to access it as</span>
    <span class="c1"># a property. Just remove it so that it doesn&#39;t show up</span>
    <span class="c1"># at all as a property any more.</span>
    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="p">,</span> <span class="s1">&#39;adsorbate_info&#39;</span><span class="p">):</span>
        <span class="nb">delattr</span><span class="p">(</span><span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="p">,</span> <span class="s1">&#39;adsorbate_info&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
    <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span><span class="s2">&quot;mandatory dependency ase cannot be imported. Install using &#39;pip install ase&#39;.&quot;</span><span class="p">)</span>

<span class="k">if</span> <span class="s1">&#39;phonopy&#39;</span> <span class="ow">in</span> <span class="n">available_modules</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">phonopy.structure.atoms</span> <span class="k">import</span> <span class="n">Atoms</span> <span class="k">as</span> <span class="n">PhonopyAtoms</span>

<span class="n">get_lattice_params_</span> <span class="o">=</span> <span class="n">get_lattice_params</span>

<div class="viewcode-block" id="get_lattice_params"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.get_lattice_params">[docs]</a><span class="k">def</span> <span class="nf">get_lattice_params</span><span class="p">(</span><span class="n">lattice</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Wrapper around Fortran :func:`get_lattice_params_`</span>

<span class="sd">    Returns parameters of `lattice` as 6-tuple (a,b,c,alpha,beta,gamma).</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">,</span><span class="n">alpha</span><span class="p">,</span><span class="n">beta</span><span class="p">,</span><span class="n">gamma</span> <span class="o">=</span> <span class="p">(</span><span class="n">farray</span><span class="p">(</span><span class="mf">0.</span><span class="p">),</span> <span class="n">farray</span><span class="p">(</span><span class="mf">0.</span><span class="p">),</span> <span class="n">farray</span><span class="p">(</span><span class="mf">0.</span><span class="p">),</span>
                              <span class="n">farray</span><span class="p">(</span><span class="mf">0.</span><span class="p">),</span> <span class="n">farray</span><span class="p">(</span><span class="mf">0.</span><span class="p">),</span> <span class="n">farray</span><span class="p">(</span><span class="mf">0.</span><span class="p">))</span>
    <span class="n">_atoms</span><span class="o">.</span><span class="n">get_lattice_params</span><span class="p">(</span><span class="n">lattice</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">,</span><span class="n">alpha</span><span class="p">,</span><span class="n">beta</span><span class="p">,</span><span class="n">gamma</span><span class="p">)</span>
    <span class="k">return</span> <span class="nb">tuple</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">,</span><span class="n">alpha</span><span class="p">,</span><span class="n">beta</span><span class="p">,</span><span class="n">gamma</span><span class="p">))</span></div>

<span class="k">class</span> <span class="nc">NeighbourInfo</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Store information about a single neighbour of an atom&quot;&quot;&quot;</span>

    <span class="vm">__slots__</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;j&#39;</span><span class="p">,</span> <span class="s1">&#39;distance&#39;</span><span class="p">,</span> <span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;cosines&#39;</span><span class="p">,</span> <span class="s1">&#39;shift&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">distance</span><span class="p">,</span> <span class="n">diff</span><span class="p">,</span> <span class="n">cosines</span><span class="p">,</span> <span class="n">shift</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">j</span> <span class="o">=</span> <span class="n">j</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">distance</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">distance</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diff</span> <span class="o">=</span> <span class="n">diff</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cosines</span> <span class="o">=</span> <span class="n">cosines</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">shift</span> <span class="o">=</span> <span class="n">shift</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">__int__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">j</span>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">(</span><span class="s1">&#39;NeighbourInfo(j=</span><span class="si">%d</span><span class="s1">,distance=</span><span class="si">%f</span><span class="s1">,diff=</span><span class="si">%s</span><span class="s1">,cosines=</span><span class="si">%s</span><span class="s1">,shift=</span><span class="si">%s</span><span class="s1">)&#39;</span>
                    <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">j</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">distance</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">diff</span><span class="p">,</span>
                       <span class="bp">self</span><span class="o">.</span><span class="n">cosines</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">shift</span><span class="p">))</span>

<div class="viewcode-block" id="Connection"><a class="viewcode-back" href="../../connection.html#quippy.atoms.Connection">[docs]</a><span class="k">class</span> <span class="nc">Connection</span><span class="p">(</span><span class="n">_atoms</span><span class="o">.</span><span class="n">Connection</span><span class="p">):</span>
    <span class="vm">__doc__</span> <span class="o">=</span> <span class="n">update_doc_string</span><span class="p">(</span><span class="n">_atoms</span><span class="o">.</span><span class="n">Connection</span><span class="o">.</span><span class="vm">__doc__</span><span class="p">,</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">    The :class:`Connection` is a subclass of :class:`_atoms.Connection`</span>
<span class="s2">    which adds supports for iteration over all atoms, and indexing</span>
<span class="s2">    e.g. ``at.connect.neighbours[1]`` returns a list of the neighbours of</span>
<span class="s2">    the atom with index 1.</span>

<span class="s2">    When indexed with an integer from 1 to `at.n`, returns an array</span>
<span class="s2">    of :class:`NeighbourInfo` objects, each of which corresponds to</span>
<span class="s2">    a particular pair `(i,j)` and has attributes `j`, `distance`,</span>
<span class="s2">    `diff`, `cosines` and `shift`.</span>

<span class="s2">    If ``fortran_indexing`` is True, atom and neighbour indices</span>
<span class="s2">    start from 1; otherwise they are numbered from zero.</span>

<span class="s2">    If connectivity information has not already been calculated</span>
<span class="s2">    :meth:`calc_connect` will be called automatically. The code to</span>
<span class="s2">    loop over the neighbours of all atoms is quite idiomatic::</span>

<span class="s2">        for i in at.indices:</span>
<span class="s2">           for neighb in at.connect[i]:</span>
<span class="s2">               print (neighb.j, neighb.distance, neighb.diff,</span>
<span class="s2">                      neighb.cosines, neighb.shift)</span>

<span class="s2">    Note that this provides a more Pythonic interface to the atomic</span>
<span class="s2">    connectivity information than the wrapped Fortran functions</span>
<span class="s2">    :meth:`Atoms.n_neighbours` and :meth:`Atoms.neighbour`.</span>
<span class="s2">    &quot;&quot;&quot;</span><span class="p">)</span>

    <span class="c1"># def __init__(self, n=None, nbuffer=None, pos=None,</span>
    <span class="c1">#              lattice=None, g=None, origin=None,</span>
    <span class="c1">#              extent=None, nn_guess=None, fill=None,</span>
    <span class="c1">#              fpointer=None, finalise=True):</span>
    <span class="c1">#     _atoms.Connection.__init__(self, n, nbuffer, pos,</span>
    <span class="c1">#                                lattice, g, origin,</span>
    <span class="c1">#                                extent, nn_guess, fill,</span>
    <span class="c1">#                                fpointer, finalise)</span>


    <span class="k">def</span> <span class="nf">is_neighbour</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pairs</span><span class="p">()</span>

<div class="viewcode-block" id="Connection.pairs"><a class="viewcode-back" href="../../connection.html#quippy.atoms.Connection.pairs">[docs]</a>    <span class="k">def</span> <span class="nf">pairs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Yield pairs of atoms (i,j) with i &lt; j which are neighbours&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">neighbour_list</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">indices</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">iterneighbours</span><span class="p">()):</span>
            <span class="k">for</span> <span class="n">neighb</span> <span class="ow">in</span> <span class="n">neighbour_list</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">neighb</span><span class="o">.</span><span class="n">j</span><span class="p">:</span>
                    <span class="k">yield</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">neighb</span><span class="o">.</span><span class="n">j</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="c1"># Neighbours are considered to be equal if *topology* matches,</span>
        <span class="c1"># not distances, displacement vectors and shifts.</span>
        <span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pairs</span><span class="p">())</span> <span class="o">==</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">pairs</span><span class="p">())</span>

    <span class="k">def</span> <span class="nf">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__eq__</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">iterneighbours</span><span class="p">()</span>

<div class="viewcode-block" id="Connection.iterneighbours"><a class="viewcode-back" href="../../connection.html#quippy.atoms.Connection.iterneighbours">[docs]</a>    <span class="k">def</span> <span class="nf">iterneighbours</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Iterate over the neighbours of all atoms&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">indices</span><span class="p">:</span>
            <span class="k">yield</span> <span class="bp">self</span><span class="p">[</span><span class="n">i</span><span class="p">]</span></div>

    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">initialised</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span> <span class="ow">is</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">hysteretic_connect</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">calc_connect_hysteretic</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">calc_connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">)</span>

        <span class="n">distance</span> <span class="o">=</span> <span class="n">farray</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="n">diff</span> <span class="o">=</span> <span class="n">fzeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="n">cosines</span> <span class="o">=</span> <span class="n">fzeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="n">shift</span> <span class="o">=</span> <span class="n">fzeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">)</span>

        <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">get_fortran_indexing</span><span class="p">():</span>
            <span class="n">i</span> <span class="o">=</span> <span class="n">i</span><span class="o">+</span><span class="mi">1</span> <span class="c1"># convert to 1-based indexing</span>

        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">frange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n_neighbours</span><span class="p">(</span><span class="n">i</span><span class="p">)):</span>
            <span class="n">j</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbour</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">distance</span><span class="p">,</span> <span class="n">diff</span><span class="p">,</span>
                               <span class="n">cosines</span><span class="p">,</span> <span class="n">shift</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">get_fortran_indexing</span><span class="p">():</span>
                <span class="n">j</span> <span class="o">=</span> <span class="n">j</span><span class="o">-</span><span class="mi">1</span>
            <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">NeighbourInfo</span><span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="n">distance</span><span class="p">,</span> <span class="n">diff</span><span class="p">,</span> <span class="n">cosines</span><span class="p">,</span> <span class="n">shift</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">get_fortran_indexing</span><span class="p">():</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">farray</span><span class="p">(</span><span class="n">res</span><span class="p">)</span> <span class="c1"># to give 1-based indexing</span>
        <span class="k">return</span> <span class="n">res</span>

<div class="viewcode-block" id="Connection.distances"><a class="viewcode-back" href="../../connection.html#quippy.atoms.Connection.distances">[docs]</a>    <span class="k">def</span> <span class="nf">distances</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">Z1</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">Z2</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Distances between pairs of neighbours, optionally</span>
<span class="sd">           filtered by species (Z1,Z2)&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">indices</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">neighb</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">neighb</span><span class="o">.</span><span class="n">j</span> <span class="o">&gt;</span> <span class="n">i</span><span class="p">:</span> <span class="k">continue</span>
                <span class="k">if</span> <span class="n">Z1</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">Z2</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">sorted</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">z</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">z</span><span class="p">[</span><span class="n">neighb</span><span class="o">.</span><span class="n">j</span><span class="p">]))</span> <span class="o">==</span> <span class="nb">sorted</span><span class="p">((</span><span class="n">Z1</span><span class="p">,</span> <span class="n">Z2</span><span class="p">)):</span>
                        <span class="k">yield</span> <span class="n">neighb</span><span class="o">.</span><span class="n">distance</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">yield</span> <span class="n">neighb</span><span class="o">.</span><span class="n">distance</span></div>

<div class="viewcode-block" id="Connection.get_neighbours"><a class="viewcode-back" href="../../connection.html#quippy.atoms.Connection.get_neighbours">[docs]</a>    <span class="k">def</span> <span class="nf">get_neighbours</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return neighbours of atom i</span>

<span class="sd">        Return arrays of indices and offsets to neighbouring</span>
<span class="sd">        atoms. The positions of the neighbor atoms can be calculated like</span>
<span class="sd">        this::</span>

<span class="sd">            indices, offsets = atoms.connect.get_neighbors(42)</span>
<span class="sd">            for i, offset in zip(indices, offsets):</span>
<span class="sd">               print atoms.positions[i] + dot(offset, atoms.get_cell())</span>

<span class="sd">        Compatible with ase.calculators.neighborlist.NeighborList.get_neighbors(),</span>
<span class="sd">        providing that NeighborList is constructed with bothways=True and</span>
<span class="sd">        self_interaction=False.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">neighbours</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="n">indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">n</span><span class="o">.</span><span class="n">j</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">neighbours</span><span class="p">])</span>
        <span class="n">offsets</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">r_</span><span class="p">[[</span><span class="n">n</span><span class="o">.</span><span class="n">shift</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">neighbours</span><span class="p">]]</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">indices</span><span class="p">,</span> <span class="n">offsets</span><span class="p">)</span></div>


<div class="viewcode-block" id="Connection.get_neighbors"><a class="viewcode-back" href="../../connection.html#quippy.atoms.Connection.get_neighbors">[docs]</a>    <span class="k">def</span> <span class="nf">get_neighbors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Variant spelling of :meth:`get_neighbours`</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_neighbours</span><span class="p">(</span><span class="n">i</span><span class="p">)</span></div></div>


<span class="k">class</span> <span class="nc">PropertiesWrapper</span><span class="p">(</span><span class="n">DictMixin</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Wrapper between quippy properties and ASE arrays&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">at</span><span class="p">):</span>
        <span class="n">DictMixin</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">atref</span> <span class="o">=</span> <span class="n">weakref</span><span class="o">.</span><span class="n">ref</span><span class="p">(</span><span class="n">at</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atref</span><span class="p">()</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="n">at</span><span class="o">.</span><span class="n">name_map</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">key</span><span class="p">)]</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
        <span class="c1">#if res.dtype == &#39;int32&#39;:   # convert dtype int32 -&gt; int</span>
        <span class="c1">#    res = res.astype(int)</span>
        <span class="c1">#    atomslog.debug(&#39;Making copy of arrays[&quot;%s&quot;] since quippy/ASE dtypes incompatible&#39; % key)</span>
        <span class="k">return</span> <span class="n">res</span>

    <span class="k">def</span> <span class="nf">__setitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atref</span><span class="p">()</span>
        <span class="n">atomslog</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Setting arrays[&quot;</span><span class="si">%s</span><span class="s1">&quot;]&#39;</span> <span class="o">%</span> <span class="n">key</span><span class="p">)</span>
        <span class="n">key</span> <span class="o">=</span> <span class="n">Atoms</span><span class="o">.</span><span class="n">name_map</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span>
        <span class="n">value</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">at</span><span class="o">.</span><span class="n">n</span><span class="p">:</span>
            <span class="n">atomslog</span><span class="o">.</span><span class="n">debug</span><span class="p">((</span><span class="s1">&#39;Assignment to arrays[&quot;</span><span class="si">%s</span><span class="s1">&quot;]: changing size &#39;</span><span class="o">+</span>
                           <span class="s1">&#39; from </span><span class="si">%d</span><span class="s1"> to </span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span> <span class="o">%</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">at</span><span class="o">.</span><span class="n">n</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="n">at</span><span class="o">.</span><span class="n">remove_property</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">at</span><span class="o">.</span><span class="n">n</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">at</span><span class="o">.</span><span class="n">nbuffer</span> <span class="o">=</span> <span class="n">at</span><span class="o">.</span><span class="n">n</span>
            <span class="n">at</span><span class="o">.</span><span class="n">ndomain</span> <span class="o">=</span> <span class="n">at</span><span class="o">.</span><span class="n">n</span>

        <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">dtype</span><span class="o">.</span><span class="n">kind</span> <span class="o">!=</span> <span class="s1">&#39;S&#39;</span><span class="p">:</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">T</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">at</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="n">key</span><span class="p">):</span>
            <span class="n">at</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="k">def</span> <span class="nf">__delitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atref</span><span class="p">()</span>
        <span class="n">atomslog</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Deletion of arrays[&quot;</span><span class="si">%s</span><span class="s1">&quot;]&#39;</span> <span class="o">%</span> <span class="n">key</span><span class="p">)</span>
        <span class="n">key</span> <span class="o">=</span> <span class="n">at</span><span class="o">.</span><span class="n">name_map</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span>
        <span class="n">at</span><span class="o">.</span><span class="n">remove_property</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">keys</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atref</span><span class="p">()</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">at</span><span class="o">.</span><span class="n">rev_name_map</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">keys</span><span class="p">()]</span>


<div class="viewcode-block" id="Atoms"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms">[docs]</a><span class="k">class</span> <span class="nc">Atoms</span><span class="p">(</span><span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="p">,</span> <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="p">):</span>
    <span class="vm">__doc__</span> <span class="o">=</span> <span class="n">update_doc_string</span><span class="p">(</span><span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="vm">__doc__</span><span class="p">,</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">    The :class:`Atoms` class is a Pythonic wrapper over the auto-generated</span>
<span class="s2">    :class:`quippy._atoms.Atoms` class. Atoms object are usually</span>
<span class="s2">    constructed either by reading from an input file in one of the</span>
<span class="s2">    :ref:`fileformats`, or by using the structure creation functions in</span>
<span class="s2">    the :mod:`quippy.structures` or :mod:`ase.lattice` modules.</span>

<span class="s2">    For example to read from an :ref:`extendedxyz` file, use::</span>

<span class="s2">       from quippy.atoms import Atoms</span>
<span class="s2">       atoms = Atoms(&#39;filename.xyz&#39;)</span>

<span class="s2">    Or, to create an 8-atom bulk diamond cubic cell of silicon::</span>

<span class="s2">       from quippy.structures import diamond</span>
<span class="s2">       si_bulk = diamond(5.44, 14)</span>

<span class="s2">    The :class:`Atoms` class is inherited from the</span>
<span class="s2">    :class:`ase.atoms.Atoms` so has all the ASE Atoms attributes and</span>
<span class="s2">    methods. This means that quippy and ASE Atoms objects are fully</span>
<span class="s2">    interoperable.&quot;&quot;&quot;</span><span class="p">,</span> <span class="n">signature</span><span class="o">=</span><span class="s1">&#39;Atoms([symbols, positions, numbers, tags, momenta, masses, magmoms, charges, scaled_positions, cell, pbc, constraint, calculator, info, n, lattice, properties, params, fixed_size, **read_args])&#39;</span><span class="p">)</span>

    <span class="n">_cmp_skip_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;own_this&#39;</span><span class="p">,</span> <span class="s1">&#39;ref_count&#39;</span><span class="p">,</span> <span class="s1">&#39;domain&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;connect&#39;</span><span class="p">,</span> <span class="s1">&#39;hysteretic_connect&#39;</span><span class="p">,</span> <span class="s1">&#39;source&#39;</span><span class="p">]</span>

    <span class="n">name_map</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;positions&#39;</span>       <span class="p">:</span> <span class="s1">&#39;pos&#39;</span><span class="p">,</span>
                <span class="s1">&#39;numbers&#39;</span>         <span class="p">:</span> <span class="s1">&#39;Z&#39;</span><span class="p">,</span>
                <span class="s1">&#39;initial_charges&#39;</span> <span class="p">:</span> <span class="s1">&#39;charge&#39;</span><span class="p">,</span>
                <span class="s1">&#39;initial_magmoms&#39;</span> <span class="p">:</span> <span class="s1">&#39;magmoms&#39;</span><span class="p">}</span>

    <span class="n">rev_name_map</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">name_map</span><span class="o">.</span><span class="n">values</span><span class="p">(),</span> <span class="n">name_map</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">positions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">numbers</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">momenta</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">masses</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">magmoms</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">scaled_positions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cell</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">constraint</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">calculator</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">info</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">lattice</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">properties</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fixed_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">set_species</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                 <span class="n">fpointer</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">finalise</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                 <span class="o">**</span><span class="n">readargs</span><span class="p">):</span>

        <span class="c1"># check for mutually exclusive options</span>
        <span class="k">if</span> <span class="n">cell</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">lattice</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;only one of cell and lattice can be present&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">n</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="n">cell</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">lattice</span> <span class="o">=</span> <span class="n">cell</span><span class="o">.</span><span class="n">T</span>
        <span class="k">if</span> <span class="n">lattice</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">lattice</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>

        <span class="kn">from</span> <span class="nn">quippy</span> <span class="k">import</span> <span class="n">Dictionary</span>
        <span class="k">if</span> <span class="n">properties</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">Dictionary</span><span class="p">):</span>
            <span class="n">properties</span> <span class="o">=</span> <span class="n">Dictionary</span><span class="p">(</span><span class="n">properties</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">params</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">params</span><span class="p">,</span> <span class="n">Dictionary</span><span class="p">):</span>
            <span class="n">params</span> <span class="o">=</span> <span class="n">Dictionary</span><span class="p">(</span><span class="n">params</span><span class="p">)</span>

        <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="n">n</span><span class="p">,</span> <span class="n">lattice</span><span class="o">=</span><span class="n">lattice</span><span class="p">,</span>
                              <span class="n">properties</span><span class="o">=</span><span class="n">properties</span><span class="p">,</span>
                              <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">,</span> <span class="n">fixed_size</span><span class="o">=</span><span class="n">fixed_size</span><span class="p">,</span>
                              <span class="n">fpointer</span><span class="o">=</span><span class="n">fpointer</span><span class="p">,</span> <span class="n">finalise</span><span class="o">=</span><span class="n">finalise</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_ase_arrays</span> <span class="o">=</span> <span class="n">PropertiesWrapper</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="c1"># If first argument is quippy.Atoms instance, copy data from it</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">copy_from</span><span class="p">(</span><span class="n">symbols</span><span class="p">)</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="c1"># Phonopy compatibility</span>
        <span class="k">if</span> <span class="s1">&#39;phonopy&#39;</span> <span class="ow">in</span> <span class="n">available_modules</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="n">PhonopyAtoms</span><span class="p">)):</span>
                <span class="n">atoms</span> <span class="o">=</span> <span class="n">symbols</span>
                <span class="n">symbols</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_chemical_symbols</span><span class="p">()</span>
                <span class="n">cell</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()</span>
                <span class="n">positions</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_positions</span><span class="p">()</span>
                <span class="n">masses</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()</span>

        <span class="c1"># Try to read from first argument, if it&#39;s not ase.Atoms</span>
        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_from</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="o">**</span><span class="n">readargs</span><span class="p">)</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="c1">## ASE compatibility</span>
        <span class="n">remove_properties</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">numbers</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;z&#39;</span><span class="p">):</span>
                <span class="n">numbers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">numbers</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
                <span class="n">remove_properties</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">positions</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;pos&#39;</span><span class="p">):</span>
                <span class="n">positions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pos</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">remove_properties</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;pos&#39;</span><span class="p">)</span>

        <span class="c1"># Make sure argument to ase.Atoms constructor are consistent with</span>
        <span class="c1"># properties already present in this Atoms object</span>
        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">momenta</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;momenta&#39;</span><span class="p">):</span>
            <span class="n">momenta</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_momenta</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">masses</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;masses&#39;</span><span class="p">):</span>
            <span class="n">masses</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">cell</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">T</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">pbc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_pbc</span><span class="p">()</span>
            <span class="c1">#print &#39;setting pbc to &#39;, pbc</span>
        <span class="k">if</span> <span class="n">charges</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;charge&#39;</span><span class="p">):</span>
            <span class="n">charges</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">charge</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span>

        <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">positions</span><span class="p">,</span> <span class="n">numbers</span><span class="p">,</span>
                           <span class="n">tags</span><span class="p">,</span> <span class="n">momenta</span><span class="p">,</span> <span class="n">masses</span><span class="p">,</span> <span class="n">magmoms</span><span class="p">,</span> <span class="n">charges</span><span class="p">,</span>
                           <span class="n">scaled_positions</span><span class="p">,</span> <span class="n">cell</span><span class="p">,</span> <span class="n">pbc</span><span class="p">,</span> <span class="n">constraint</span><span class="p">,</span>
                           <span class="n">calculator</span><span class="p">)</span>

        <span class="c1"># remove anything that ASE added that we don&#39;t want</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">remove_properties</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">remove_property</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">copy_from</span><span class="p">(</span><span class="n">symbols</span><span class="p">)</span>

        <span class="c1">## end ASE compatibility</span>

        <span class="k">if</span> <span class="n">set_species</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="o">*</span><span class="n">TABLE_STRING_LENGTH</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">():</span>
                <span class="n">mass</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;mass&#39;</span><span class="p">):</span>
                    <span class="n">mass</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">set_atoms</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="n">mass</span><span class="o">=</span><span class="n">mass</span><span class="p">)</span> <span class="c1"># initialise species from z</span>

        <span class="k">if</span> <span class="n">info</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">info</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_initialised</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="c1"># synonyms for backwards compatibility</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">neighbours</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">connect</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">hysteretic_neighbours</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">hysteretic_connect</span>


<div class="viewcode-block" id="Atoms.set_atomic_numbers"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_atomic_numbers">[docs]</a>    <span class="k">def</span> <span class="nf">set_atomic_numbers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">numbers</span><span class="p">,</span> <span class="n">set_species</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set atomic numbers and optionally also species property (default True)&quot;&quot;&quot;</span>
        <span class="c1"># override ase.Atoms.set_atomic_numbers() to keep QUIP Z and species in sync</span>
        <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="n">set_atomic_numbers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">numbers</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">set_species</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="o">*</span><span class="n">TABLE_STRING_LENGTH</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">():</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">set_atoms</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">)</span> <span class="c1"># set species from Z</span></div>

<div class="viewcode-block" id="Atoms.set_chemical_symbols"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_chemical_symbols">[docs]</a>    <span class="k">def</span> <span class="nf">set_chemical_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">set_species</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set chemical symbols - sets Z and optionally also species properties (default True)&quot;&quot;&quot;</span>
        <span class="c1"># override ase.Atoms.set_chemical_symbols() to keep QUIP Z and species in sync</span>
        <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="n">set_chemical_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">set_species</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="o">*</span><span class="n">TABLE_STRING_LENGTH</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">():</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">set_atoms</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">)</span> <span class="c1"># set species from Z</span></div>

<div class="viewcode-block" id="Atoms.new_array"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.new_array">[docs]</a>    <span class="k">def</span> <span class="nf">new_array</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="c1"># we overrride ase.Atoms.new_array() to allow &quot;special&quot; arrays</span>
        <span class="c1"># like &quot;numbers&quot;, &quot;positions&quot; to be added more than once without</span>
        <span class="c1"># raising a RuntimeError</span>
        <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_map</span> <span class="ow">and</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span>
            <span class="k">return</span>
        <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="n">new_array</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">shape</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.set_lattice"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_lattice">[docs]</a>    <span class="k">def</span> <span class="nf">set_lattice</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">scale_positions</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Change the lattice vectors, keeping the inverse lattice vectors</span>
<span class="sd">           up to date. Optionally map the existing atoms into the new cell</span>
<span class="sd">           and recalculate connectivity (by default scale_positions=False).&quot;&quot;&quot;</span>
        <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="n">set_lattice</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">scale_positions</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">_get_cell</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get ASE cell from QUIP lattice&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>

    <span class="k">def</span> <span class="nf">_set_cell</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cell</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set QUIP lattice from ASE cell&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_lattice</span><span class="p">(</span><span class="n">cell</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">scale_positions</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

    <span class="n">_cell</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_cell</span><span class="p">,</span> <span class="n">_set_cell</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_pbc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pbc</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_periodic</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">pbc</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_pbc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_periodic</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span> <span class="o">==</span> <span class="n">QUIPPY_TRUE</span>

    <span class="n">_pbc</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_pbc</span><span class="p">,</span> <span class="n">_set_pbc</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_ase_arrays</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Provides access to ASE arrays, stored in QUIP properties dict&quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ase_arrays</span>

    <span class="k">def</span> <span class="nf">_set_ase_arrays</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set ASE arrays. Does not remove existing QUIP properties.&quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_ase_arrays</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

    <span class="n">arrays</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_ase_arrays</span><span class="p">,</span> <span class="n">_set_ase_arrays</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;ASE info dictionary</span>

<span class="sd">        Entries are actually stored in QUIP params dictionary.&quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span>

    <span class="k">def</span> <span class="nf">_set_info</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set ASE info dictionary.</span>

<span class="sd">        Entries are actually stored in QUIP params dictionary.</span>
<span class="sd">        Note that clearing Atoms.info doesn&#39;t empty params</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

    <span class="n">info</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_info</span><span class="p">,</span> <span class="n">_set_info</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_indices</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return array of atoms indices</span>

<span class="sd">        If global ``fortran_indexing`` is True, returns FortranArray containing</span>
<span class="sd">        numbers 1..self.n.  Otherwise, returns a standard numpuy array</span>
<span class="sd">        containing numbers in range 0..(self.n-1).&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">get_fortran_indexing</span><span class="p">():</span>
            <span class="k">return</span> <span class="n">farray</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">frange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))))</span>

    <span class="n">indices</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_indices</span><span class="p">)</span>

<div class="viewcode-block" id="Atoms.iteratoms"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.iteratoms">[docs]</a>    <span class="k">def</span> <span class="nf">iteratoms</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Iterate over atoms, calling get_atom() for each one&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">indices</span><span class="p">:</span>
            <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_atom</span><span class="p">(</span><span class="n">i</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.equivalent"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.equivalent">[docs]</a>    <span class="k">def</span> <span class="nf">equivalent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Test for equivalence of two Atoms objects.</span>

<span class="sd">        Equivalence is less strong than equality.  Equality (written</span>
<span class="sd">        `self == other`) requires all properties and parameters to be</span>
<span class="sd">        equal. Equivalence requires only that the number of atoms,</span>
<span class="sd">        positions, atomic numbers, unit cell and periodic boundary</span>
<span class="sd">        conditions match.</span>

<span class="sd">        .. note::</span>

<span class="sd">            The quippy expression a.equivalent(b) has the same</span>
<span class="sd">            definition as a == b in ASE. This means that a quippy.Atoms</span>
<span class="sd">            instance can be compared with an ase.Atoms instance using</span>
<span class="sd">            this method.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span>
            <span class="n">b</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">arrays</span>
            <span class="k">return</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">other</span><span class="p">)</span> <span class="ow">and</span>
                    <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">all</span><span class="p">()</span> <span class="ow">and</span>
                    <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">all</span><span class="p">()</span> <span class="ow">and</span>
                    <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">cell</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">()</span> <span class="ow">and</span>
                    <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">pbc</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">())</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="Atoms.read"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.read">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Class method to read Atoms object from file `source` according to `format`</span>

<span class="sd">        If `format` is None, filetype is inferred from filename.</span>
<span class="sd">        Returns a new Atoms instance; to read into an existing Atoms</span>
<span class="sd">        object, use the read_from() method.</span>

<span class="sd">        If `source` corresponds to a known format then it used</span>
<span class="sd">        to construct an appropriate iterator from the :attr:`AtomsReaders`</span>
<span class="sd">        dictionary. See :ref:`fileformats` for a list of supported</span>
<span class="sd">        file formats.</span>

<span class="sd">        If `source` corresponds to an unknown format then it is</span>
<span class="sd">        expected to be an iterator returning :class:`Atoms` objects.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">basestring</span><span class="p">)</span> <span class="ow">and</span> <span class="s1">&#39;@&#39;</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">source</span><span class="p">):</span>
            <span class="n">source</span><span class="p">,</span> <span class="n">frame</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">source</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">&#39;.db&#39;</span><span class="p">):</span>
                <span class="n">source</span> <span class="o">=</span> <span class="n">source</span><span class="o">+</span><span class="s1">&#39;@&#39;</span><span class="o">+</span><span class="n">frame</span>
                <span class="nb">format</span> <span class="o">=</span> <span class="s1">&#39;db&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">frame</span> <span class="o">=</span> <span class="n">parse_slice</span><span class="p">(</span><span class="n">frame</span><span class="p">)</span>
                <span class="k">if</span> <span class="s1">&#39;frame&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Conflicting frame references given: kwarg frame=</span><span class="si">%r</span><span class="s2"> and @-reference </span><span class="si">%r</span><span class="s2">&quot;</span> <span class="o">%</span>
                                     <span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;frame&#39;</span><span class="p">],</span> <span class="n">frame</span><span class="p">))</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">frame</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Frame @-reference </span><span class="si">%r</span><span class="s2"> does not resolve to single frame&quot;</span> <span class="o">%</span> <span class="n">frame</span><span class="p">)</span>
                <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;frame&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">frame</span>

        <span class="kn">from</span> <span class="nn">quippy.io</span> <span class="k">import</span> <span class="n">AtomsReaders</span>
        <span class="n">filename</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="nb">format</span> <span class="o">=</span> <span class="n">infer_format</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="nb">format</span><span class="p">,</span> <span class="n">AtomsReaders</span><span class="p">)</span>

        <span class="n">opened</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="nb">format</span> <span class="ow">in</span> <span class="n">AtomsReaders</span><span class="p">:</span>
            <span class="n">source</span> <span class="o">=</span> <span class="n">AtomsReaders</span><span class="p">[</span><span class="nb">format</span><span class="p">](</span><span class="n">source</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="nb">format</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="n">opened</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">basestring</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s2">&quot;Don&#39;t know how to read from file &#39;</span><span class="si">%s</span><span class="s2">&#39;&quot;</span> <span class="o">%</span> <span class="n">source</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="s1">&#39;__iter__&#39;</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s1">&#39;Cannot read from </span><span class="si">%r</span><span class="s1"> - not an iterator&#39;</span> <span class="o">%</span> <span class="n">source</span><span class="p">)</span>

        <span class="n">at</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="n">source</span><span class="p">)</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">at</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Object </span><span class="si">%r</span><span class="s1"> read from  </span><span class="si">%r</span><span class="s1"> is not Atoms instance&#39;</span>
                             <span class="o">%</span> <span class="p">(</span><span class="n">at</span><span class="p">,</span> <span class="n">source</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">opened</span> <span class="ow">and</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">):</span>
            <span class="n">source</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">filename</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">at</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="k">return</span> <span class="n">at</span></div>


<div class="viewcode-block" id="Atoms.write"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.write">[docs]</a>    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">properties</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
              <span class="n">prefix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write this :class:`Atoms` object to `dest`. If `format` is</span>
<span class="sd">        absent it is inferred from the file extension or type of `dest`,</span>
<span class="sd">        as described for the :meth:`read` method.  If `properties` is</span>
<span class="sd">        present, it should be a list of property names to include in the</span>
<span class="sd">        output file, e.g. `[&#39;species&#39;, &#39;pos&#39;]`.</span>

<span class="sd">        See :ref:`fileformats` for a list of supported file formats.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">dest</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># if filename is missing, save back to file from</span>
            <span class="c1"># which we loaded configuration</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;filename&#39;</span><span class="p">):</span>
                <span class="n">dest</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">filename</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;No &#39;dest&#39; and Atoms has no stored filename&quot;</span><span class="p">)</span>

        <span class="kn">from</span> <span class="nn">quippy.io</span> <span class="k">import</span> <span class="n">AtomsWriters</span>
        <span class="n">filename</span><span class="p">,</span> <span class="n">dest</span><span class="p">,</span> <span class="nb">format</span> <span class="o">=</span> <span class="n">infer_format</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="nb">format</span><span class="p">,</span> <span class="n">AtomsWriters</span><span class="p">)</span>
        <span class="n">opened</span> <span class="o">=</span> <span class="n">filename</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="nb">format</span> <span class="ow">in</span> <span class="n">AtomsWriters</span><span class="p">:</span>
            <span class="n">dest</span> <span class="o">=</span> <span class="n">AtomsWriters</span><span class="p">[</span><span class="nb">format</span><span class="p">](</span><span class="n">dest</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="s1">&#39;write&#39;</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Don</span><span class="se">\&#39;</span><span class="s1">t know how to write to &quot;</span><span class="si">%s</span><span class="s1">&quot; in format &quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span>
                             <span class="o">%</span> <span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="nb">format</span><span class="p">))</span>

        <span class="n">write_kwargs</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">properties</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">write_kwargs</span><span class="p">[</span><span class="s1">&#39;properties&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">properties</span>
        <span class="k">if</span> <span class="n">prefix</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">write_kwargs</span><span class="p">[</span><span class="s1">&#39;prefix&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">prefix</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">dest</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">write_kwargs</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;destination </span><span class="si">%r</span><span class="s1"> doesn</span><span class="se">\&#39;</span><span class="s1">t support arguments </span><span class="si">%r</span><span class="s1">&#39;</span>
                             <span class="o">%</span> <span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="n">write_kwargs</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">opened</span> <span class="ow">and</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">):</span>
            <span class="n">dest</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">res</span></div>

<div class="viewcode-block" id="Atoms.select"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.select">[docs]</a>    <span class="k">def</span> <span class="nf">select</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="nb">list</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">orig_index</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a new :class:`Atoms` containing a subset of the atoms in this Atoms object</span>

<span class="sd">        One of either `mask` or `list` should be present.  If `mask`</span>
<span class="sd">        is given it should be a rank one array of length `self.n`. In</span>
<span class="sd">        this case atoms corresponding to true values in `mask` will be</span>
<span class="sd">        included in the result.  If `list` is present it should be an</span>
<span class="sd">        arry of list containing atom indices to include in the result.</span>

<span class="sd">        If `orig_index` is True (default), the new object will contain</span>
<span class="sd">        an ``orig_index`` property mapping the indices of the new atoms</span>
<span class="sd">        back to the original larger Atoms object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">mask</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">mask</span> <span class="o">=</span> <span class="n">farray</span><span class="p">(</span><span class="n">mask</span><span class="p">)</span>
            <span class="n">out</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="n">mask</span><span class="o">.</span><span class="n">sum</span><span class="p">(),</span> <span class="n">lattice</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span> <span class="n">properties</span><span class="o">=</span><span class="p">{},</span> <span class="n">params</span><span class="o">=</span><span class="p">{})</span>
            <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="n">mask</span><span class="p">,</span> <span class="n">orig_index</span><span class="o">=</span><span class="n">orig_index</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">list</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="nb">list</span> <span class="o">=</span> <span class="n">farray</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
            <span class="n">out</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">),</span> <span class="n">lattice</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">lattice</span><span class="p">)</span>
            <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="nb">list</span><span class="o">=</span><span class="nb">list</span><span class="p">,</span> <span class="n">orig_index</span><span class="o">=</span><span class="n">orig_index</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Either mask or list must be present.&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">out</span></div>


<div class="viewcode-block" id="Atoms.copy"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return a copy of this :class:`Atoms` object</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">other</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">,</span> <span class="n">lattice</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
                               <span class="n">properties</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">)</span>

        <span class="c1"># copy any normal (not Fortran) attributes</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">k</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;_&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">:</span>
                <span class="n">other</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>

        <span class="c1"># from _atoms.Atoms</span>
        <span class="n">other</span><span class="o">.</span><span class="n">cutoff</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cutoff</span>
        <span class="n">other</span><span class="o">.</span><span class="n">cutoff_skin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cutoff_skin</span>
        <span class="n">other</span><span class="o">.</span><span class="n">nneightol</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nneightol</span>

        <span class="c1"># from ase.Atoms</span>
        <span class="n">other</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">other</span></div>

<div class="viewcode-block" id="Atoms.copy_from"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.copy_from">[docs]</a>    <span class="k">def</span> <span class="nf">copy_from</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Replace contents of this Atoms object with data from `other`.&quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="fm">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="p">):</span>
            <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="n">other</span><span class="o">.</span><span class="n">n</span><span class="p">,</span> <span class="n">lattice</span><span class="o">=</span><span class="n">other</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
                                  <span class="n">properties</span><span class="o">=</span><span class="n">other</span><span class="o">.</span><span class="n">properties</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">other</span><span class="o">.</span><span class="n">params</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">cutoff</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">cutoff</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cutoff_skin</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">cutoff_skin</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nneightol</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">nneightol</span>

        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="p">):</span>
            <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">lattice</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
            <span class="n">ase</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span>

            <span class="c1"># copy params/info dicts</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="s1">&#39;params&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">params</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="s1">&#39;info&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">)</span>
                <span class="k">if</span> <span class="s1">&#39;nneightol&#39;</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">nneightol</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="s1">&#39;nneightol&#39;</span><span class="p">]</span>
                <span class="k">if</span> <span class="s1">&#39;cutoff&#39;</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">set_cutoff</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="s1">&#39;cutoff&#39;</span><span class="p">],</span>
                                    <span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;cutoff_break&#39;</span><span class="p">))</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;spacegroup&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span> <span class="n">Spacegroup</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;spacegroup&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="s1">&#39;spacegroup&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">symbol</span>

            <span class="c1"># create extra properties for any non-standard arrays</span>
            <span class="n">standard_ase_arrays</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">,</span> <span class="s1">&#39;numbers&#39;</span><span class="p">,</span> <span class="s1">&#39;masses&#39;</span><span class="p">,</span> <span class="s1">&#39;initial_charges&#39;</span><span class="p">,</span>
                                   <span class="s1">&#39;momenta&#39;</span><span class="p">,</span> <span class="s1">&#39;tags&#39;</span><span class="p">,</span> <span class="s1">&#39;initial_magmoms&#39;</span> <span class="p">]</span>

            <span class="k">for</span> <span class="n">ase_name</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
                <span class="n">quippy_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_map</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ase_name</span><span class="p">,</span> <span class="n">ase_name</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">ase_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">standard_ase_arrays</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="n">quippy_name</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">constraints</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;can only copy from instances of quippy.Atoms or ase.Atoms&#39;</span><span class="p">)</span>

        <span class="c1"># copy any normal (not Fortran) attributes</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">k</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;_&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span></div>


<div class="viewcode-block" id="Atoms.read_from"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.read_from">[docs]</a>    <span class="k">def</span> <span class="nf">read_from</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">readargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Replace contents of this Atoms object with Atoms read from `source`&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">copy_from</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
            <span class="n">tmp</span> <span class="o">=</span> <span class="n">Atoms</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">readargs</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">shallow_copy_from</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span></div>
            <span class="c1"># tmp goes out of scope here, but reference counting</span>
            <span class="c1"># prevents it from being free&#39;d.</span>

    <span class="k">def</span> <span class="nf">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="c1">#print &#39;getattr&#39;, name</span>
        <span class="c1">#if name in self.properties:</span>
        <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;_fpointer&#39;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s1">&#39;Atoms object not initialised!&#39;</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s1">&#39;Unknown Atoms attribute </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="c1">#print &#39;setattr&#39;, name, value</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="s1">&#39;_initialised&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">:</span>
            <span class="nb">object</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">_fpointer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="n">name</span><span class="p">][</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">_fpointer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">is_array</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="n">name</span><span class="p">][</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="nb">object</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

<div class="viewcode-block" id="Atoms.md5_hash"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.md5_hash">[docs]</a>    <span class="k">def</span> <span class="nf">md5_hash</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndigits</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Hash an atoms object with a precision of ndigits decimal</span>
<span class="sd">        digits.  Atomic numbers, lattice and fractional positions are</span>
<span class="sd">        fed to MD5 to form the hash.&quot;&quot;&quot;</span>

        <span class="k">def</span> <span class="nf">rounded_string_rep</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">ndigits</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array2string</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">precision</span><span class="o">=</span><span class="n">ndigits</span><span class="p">,</span> <span class="n">suppress_small</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;-0. &#39;</span><span class="p">,</span> <span class="s1">&#39; 0. &#39;</span><span class="p">)</span>

        <span class="c1"># Compute fractional positions, round them to ndigits, then sort them</span>
        <span class="c1"># for hash stability</span>
        <span class="n">flat_frac_pos</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">pos</span><span class="p">)</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
        <span class="n">flat_frac_pos</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>

        <span class="c1"># md5 module deprecated in Python 2.5 and later</span>
        <span class="k">try</span><span class="p">:</span>
           <span class="kn">import</span> <span class="nn">hashlib</span>
           <span class="n">md5</span> <span class="o">=</span> <span class="n">hashlib</span><span class="o">.</span><span class="n">md5</span>
        <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
           <span class="kn">import</span> <span class="nn">md5</span>
           <span class="n">md5</span> <span class="o">=</span> <span class="n">md5</span><span class="o">.</span><span class="n">new</span>

        <span class="n">m</span> <span class="o">=</span> <span class="n">md5</span><span class="p">()</span>
        <span class="n">m</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">rounded_string_rep</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">flatten</span><span class="p">(),</span> <span class="n">ndigits</span><span class="p">))</span>
        <span class="n">m</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">))</span>
        <span class="n">m</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">rounded_string_rep</span><span class="p">(</span><span class="n">flat_frac_pos</span><span class="p">,</span> <span class="n">ndigits</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">m</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span></div>

    <span class="k">def</span> <span class="nf">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">md5_hash</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>

    <span class="c1">#def __getitem__(self, i):</span>
        <span class="c1"># we override ase.Atoms.__getitem__ so we can raise</span>
        <span class="c1"># exception if we&#39;re using fortran indexing</span>
    <span class="c1">#    if self.fortran_indexing:</span>
    <span class="c1">#        raise RuntimeError(&#39;Atoms[i] inconsistent with fortran indexing&#39;)</span>
    <span class="c1">#    return ase.Atoms.__getitem__(self, i)</span>

<div class="viewcode-block" id="Atoms.get_atom"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_atom">[docs]</a>    <span class="k">def</span> <span class="nf">get_atom</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a dictionary containing the properties of the atom with</span>
<span class="sd">           index `i`. If fortran_indexing=True (the default), `i` should be in</span>
<span class="sd">           range 1..self.n, otherwise it should be in range 0..(self.n-1).&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">get_fortran_indexing</span><span class="p">()</span> <span class="ow">and</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">))</span> <span class="ow">or</span> \
            <span class="p">(</span><span class="ow">not</span> <span class="n">get_fortran_indexing</span><span class="p">()</span> <span class="ow">and</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)):</span>
            <span class="k">raise</span> <span class="ne">IndexError</span><span class="p">(</span><span class="s1">&#39;Atoms index out of range&#39;</span><span class="p">)</span>
        <span class="n">atom</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">atom</span><span class="p">[</span><span class="s1">&#39;_index&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span>
        <span class="n">atom</span><span class="p">[</span><span class="s1">&#39;atoms&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="o">...</span><span class="p">,</span><span class="n">i</span><span class="p">]</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">v</span><span class="o">.</span><span class="n">dtype</span><span class="o">.</span><span class="n">kind</span> <span class="o">==</span> <span class="s1">&#39;S&#39;</span><span class="p">:</span>
                    <span class="n">v</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="k">elif</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="p">():</span>
                    <span class="n">v</span> <span class="o">=</span> <span class="n">v</span><span class="o">.</span><span class="n">item</span><span class="p">()</span>
            <span class="n">atom</span><span class="p">[</span><span class="n">k</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span> <span class="o">=</span> <span class="n">v</span>
        <span class="k">return</span> <span class="n">atom</span></div>

<div class="viewcode-block" id="Atoms.print_atom"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.print_atom">[docs]</a>    <span class="k">def</span> <span class="nf">print_atom</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Pretty-print the properties of the atom with index `i`&quot;&quot;&quot;</span>
        <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_atom</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="n">title</span> <span class="o">=</span> <span class="s1">&#39;Atom </span><span class="si">%d</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">at</span><span class="p">[</span><span class="s1">&#39;_index&#39;</span><span class="p">]</span>
        <span class="n">title</span> <span class="o">=</span> <span class="n">title</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">title</span><span class="p">)</span><span class="o">+</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span>
        <span class="n">fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;</span><span class="si">%-15s</span><span class="s1"> =  </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span><span class="n">at</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">at</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
                                            <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;_index&#39;</span><span class="p">,</span> <span class="s1">&#39;atoms&#39;</span><span class="p">]]</span>
        <span class="nb">print</span> <span class="n">title</span><span class="o">+</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">fields</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.density"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.density">[docs]</a>    <span class="k">def</span> <span class="nf">density</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Density in units of :math:`g/m^3`. If `mass` property exists,</span>
<span class="sd">           use that, otherwise we use `z` and ElementMass table.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;mass&#39;</span><span class="p">):</span>
            <span class="n">mass</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mass</span><span class="p">)</span><span class="o">/</span><span class="n">MASSCONVERT</span><span class="o">/</span><span class="mf">1.0e3</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mass</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">ElementMass</span><span class="p">[</span><span class="n">z</span><span class="p">]</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">)</span><span class="o">/</span><span class="n">MASSCONVERT</span><span class="o">/</span><span class="mf">1.0e3</span>

        <span class="k">return</span> <span class="n">mass</span><span class="o">/</span><span class="p">(</span><span class="n">N_A</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">cell_volume</span><span class="p">()</span><span class="o">*</span><span class="mf">1.0e-30</span><span class="p">)</span><span class="o">/</span><span class="mf">1.0e3</span></div>


<div class="viewcode-block" id="Atoms.add_property"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.add_property">[docs]</a>    <span class="k">def</span> <span class="nf">add_property</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">n_cols</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                     <span class="n">overwrite</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">property_type</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add a new property to this Atoms object.</span>

<span class="sd">        `name` is the name of the new property and `value` should be</span>
<span class="sd">        either a scalar or an array representing the value, which should</span>
<span class="sd">        be either integer, real, logical or string.</span>

<span class="sd">        If a scalar is given for `value` it is copied to every element</span>
<span class="sd">        in the new property.  `n_cols` can be specified to create a 2D</span>
<span class="sd">        property from a scalar initial value - the default is 1 which</span>
<span class="sd">        creates a 1D property.</span>

<span class="sd">        If an array is given for `value` it should either have shape</span>
<span class="sd">        (self.n,) for a 1D property or (n_cols,self.n) for a 2D</span>
<span class="sd">        property.  In this case `n_cols` is inferred from the shape of</span>
<span class="sd">        the `value` and shouldn&#39;t be passed as an argument.</span>

<span class="sd">        If `property_type` is present, then no attempt is made to</span>
<span class="sd">        infer the type from `value`. This is necessary to resolve</span>
<span class="sd">        ambiguity between integer and logical types.</span>

<span class="sd">        If property with the same type is already present then no error</span>
<span class="sd">        occurs.If `overwrite` is true, the value will be overwritten with</span>
<span class="sd">        that given in `value`, otherwise the old value is retained.</span>

<span class="sd">        Here are some examples::</span>

<span class="sd">            a = Atoms(n=10, lattice=10.0*fidentity(3))</span>

<span class="sd">            a.add_property(&#39;mark&#39;, 1)                  # Scalar integer</span>
<span class="sd">            a.add_property(&#39;bool&#39;, False)              # Scalar logical</span>
<span class="sd">            a.add_property(&#39;local_energy&#39;, 0.0)        # Scalar real</span>
<span class="sd">            a.add_property(&#39;force&#39;, 0.0, n_cols=3)     # Vector real</span>
<span class="sd">            a.add_property(&#39;label&#39;, &#39;&#39;)                # Scalar string</span>

<span class="sd">            a.add_property(&#39;count&#39;, [1,2,3,4,5,6,7,8,9,10])  # From list</span>
<span class="sd">            a.add_property(&#39;norm_pos&#39;, a.pos.norm())         # From 1D array</span>
<span class="sd">            a.add_property(&#39;pos&#39;, new_pos)                   # Overwrite positions with array new_pos</span>
<span class="sd">                                                             # which should have shape (3,10)</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">n_cols</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;n_cols&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">n_cols</span>
        <span class="k">if</span> <span class="n">overwrite</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;overwrite&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">overwrite</span>

        <span class="k">if</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span> <span class="ow">and</span>
            <span class="n">value</span><span class="o">.</span><span class="n">dtype</span><span class="o">.</span><span class="n">kind</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;O&#39;</span><span class="p">,</span> <span class="s1">&#39;S&#39;</span><span class="p">]</span> <span class="ow">and</span>
            <span class="n">value</span><span class="o">.</span><span class="n">shape</span> <span class="o">!=</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="n">TABLE_STRING_LENGTH</span><span class="p">)):</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">s2a</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">&#39;str&#39;</span><span class="p">),</span> <span class="n">TABLE_STRING_LENGTH</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>

        <span class="k">if</span> <span class="n">property_type</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># override value_ref if property_type is specified</span>

            <span class="n">new_property</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

            <span class="n">type_to_value_ref</span> <span class="o">=</span> <span class="p">{</span>
               <span class="n">T_INTEGER_A</span>  <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
               <span class="n">T_REAL_A</span> <span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span>
               <span class="n">T_CHAR_A</span>  <span class="p">:</span> <span class="s2">&quot; &quot;</span><span class="o">*</span><span class="n">TABLE_STRING_LENGTH</span><span class="p">,</span>
               <span class="n">T_LOGICAL_A</span> <span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
               <span class="n">T_INTEGER_A2</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
               <span class="n">T_REAL_A2</span><span class="p">:</span> <span class="mf">0.0</span>
               <span class="p">}</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">value_ref</span> <span class="o">=</span> <span class="n">type_to_value_ref</span><span class="p">[</span><span class="n">property_type</span><span class="p">]</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Unknown property_type </span><span class="si">%d</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">property_type</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="nb">hasattr</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s1">&#39;shape&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span>
                <span class="n">property_type</span> <span class="o">!=</span> <span class="n">T_CHAR_A</span> <span class="ow">and</span> <span class="n">n_cols</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">):</span>
                <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;n_cols&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

            <span class="n">_atoms</span><span class="o">.</span><span class="n">Atoms</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value_ref</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">new_property</span> <span class="ow">or</span> <span class="n">overwrite</span><span class="p">:</span>
                <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">())[:]</span> <span class="o">=</span> <span class="n">value</span></div>

    <span class="k">def</span> <span class="nf">__getstate__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;string&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__setstate__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">state</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_from</span><span class="p">(</span><span class="n">state</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">&#39;string&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__reduce__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">Atoms</span><span class="p">,</span> <span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">__getstate__</span><span class="p">(),</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

<div class="viewcode-block" id="Atoms.mem_estimate"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.mem_estimate">[docs]</a>    <span class="k">def</span> <span class="nf">mem_estimate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Estimate memory usage of this Atoms object, in bytes&quot;&quot;&quot;</span>

        <span class="n">sizeof_table</span> <span class="o">=</span> <span class="mi">320</span>
        <span class="n">mem</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="n">p</span><span class="o">.</span><span class="n">itemsize</span><span class="o">*</span><span class="n">p</span><span class="o">.</span><span class="n">size</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">connect</span><span class="o">.</span><span class="n">initialised</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">connect</span>
            <span class="n">mem</span> <span class="o">+=</span> <span class="n">sizeof_table</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="o">*</span><span class="mi">2</span> <span class="c1"># neighbour1 and neighbour2 tables</span>
            <span class="n">mem</span> <span class="o">+=</span> <span class="mi">32</span><span class="o">*</span><span class="n">c</span><span class="o">.</span><span class="n">n_neighbours_total</span><span class="p">()</span> <span class="c1"># neighbour data</span>
            <span class="n">mem</span> <span class="o">+=</span> <span class="n">c</span><span class="o">.</span><span class="n">cell_heads</span><span class="o">.</span><span class="n">size</span><span class="o">*</span><span class="n">c</span><span class="o">.</span><span class="n">cell_heads</span><span class="o">.</span><span class="n">itemsize</span> <span class="c1"># cell data</span>

        <span class="k">return</span> <span class="n">mem</span></div>

<div class="viewcode-block" id="Atoms.extend"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.extend">[docs]</a>    <span class="k">def</span> <span class="nf">extend</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Extend atoms object by appending atoms from *other*.&quot;&quot;&quot;</span>
        <span class="c1"># modified version of ase.Atoms.extend() to work with QUIP data storage</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">ase</span><span class="o">.</span><span class="n">Atom</span><span class="p">):</span>
            <span class="n">other</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">([</span><span class="n">other</span><span class="p">])</span>

        <span class="n">n1</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="n">n2</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>

        <span class="c1"># first make a copy of self.arrays so that we can resize Atoms</span>
        <span class="n">arrays</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">([</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span> <span class="k">for</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="p">])</span>

        <span class="n">atomslog</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;old arrays </span><span class="si">%r</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">arrays</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a1</span> <span class="ow">in</span> <span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n1</span> <span class="o">+</span> <span class="n">n2</span><span class="p">,)</span> <span class="o">+</span> <span class="n">a1</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">a1</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span>
            <span class="n">a</span><span class="p">[:</span><span class="n">n1</span><span class="p">]</span> <span class="o">=</span> <span class="n">a1</span>
            <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;masses&#39;</span><span class="p">:</span>
                <span class="n">a2</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">a2</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">a2</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">a</span><span class="p">[</span><span class="n">n1</span><span class="p">:]</span> <span class="o">=</span> <span class="n">a2</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a2</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">n1</span> <span class="o">+</span> <span class="n">n2</span><span class="p">,)</span> <span class="o">+</span> <span class="n">a2</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">a2</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span>
            <span class="n">a</span><span class="p">[</span><span class="n">n1</span><span class="p">:]</span> <span class="o">=</span> <span class="n">a2</span>
            <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;masses&#39;</span><span class="p">:</span>
                <span class="n">a</span><span class="p">[:</span><span class="n">n1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()[:</span><span class="n">n1</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">a</span><span class="p">[:</span><span class="n">n1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
        <span class="n">atomslog</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;new arrays </span><span class="si">%r</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span></div>

    <span class="fm">__iadd__</span> <span class="o">=</span> <span class="n">extend</span>


    <span class="k">def</span> <span class="nf">__imul__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;In-place repeat of atoms.&quot;&quot;&quot;</span>
        <span class="c1"># modified version of ase.Atoms.extend() to work with QUIP data storage</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">m</span> <span class="o">=</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>

        <span class="n">M</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="c1"># first make a copy of self.arrays so that we can resize Atoms</span>
        <span class="n">arrays</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">([</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span> <span class="k">for</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="p">])</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">tile</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="p">(</span><span class="n">M</span><span class="p">,)</span> <span class="o">+</span> <span class="p">(</span><span class="mi">1</span><span class="p">,)</span> <span class="o">*</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">))</span>

        <span class="n">positions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>
        <span class="n">i0</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">m0</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
            <span class="k">for</span> <span class="n">m1</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
                <span class="k">for</span> <span class="n">m2</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">]):</span>
                    <span class="n">i1</span> <span class="o">=</span> <span class="n">i0</span> <span class="o">+</span> <span class="n">n</span>
                    <span class="n">positions</span><span class="p">[</span><span class="n">i0</span><span class="p">:</span><span class="n">i1</span><span class="p">]</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">((</span><span class="n">m0</span><span class="p">,</span> <span class="n">m1</span><span class="p">,</span> <span class="n">m2</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">)</span>
                    <span class="n">i0</span> <span class="o">=</span> <span class="n">i1</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">m</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)])</span>

        <span class="k">return</span> <span class="bp">self</span></div>


<span class="n">FortranDerivedTypes</span><span class="p">[</span><span class="s1">&#39;type(atoms)&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Atoms</span>
<span class="n">FortranDerivedTypes</span><span class="p">[</span><span class="s1">&#39;type(connection)&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Connection</span>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2008-2016, James Kermode

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>